home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3 / librw / RWGBitVec.z / RWGBitVec
Encoding:
Text File  |  2002-10-03  |  10.0 KB  |  265 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWGGGGBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))                                                RRRRWWWWGGGGBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWGBitVec(size) - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include <rw/gbitvec.h>
  13.  
  14.  
  15.  
  16.               declare(RWGBitVec,ssssiiiizzzzeeee)
  17.           RWGBitVec(size) a;
  18.  
  19.  
  20.  
  21.  
  22. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
  23.      RRRRWWWWGGGGBBBBiiiittttVVVVeeeecccc((((ssssiiiizzzzeeee)))) is a bit vector of fixed length ssssiiiizzzzeeee.  The length cannot
  24.      be changed dynamically (see class RRRRWWWWBBBBiiiittttVVVVeeeecccc if you need a bit vector whose
  25.      length can be changed at run time).  Objects of type RRRRWWWWGGGGBBBBiiiittttVVVVeeeecccc((((ssssiiiizzzzeeee)))) are
  26.      declared with macros defined in the standard C++ header file <<<<ggggeeeennnneeeerrrriiiicccc....hhhh>>>>.
  27.      Bits are numbered from 0 through ssssiiiizzzzeeee----1111, inclusive.
  28.  
  29. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
  30.      None
  31.  
  32. EEEExxxxaaaammmmpppplllleeee
  33.      In this example, a bit vector 24 bits long is declared and exercised:
  34.  
  35.               #include "rw/gbitvec.h"
  36.           #include <iostream.h>
  37.           const int VECSIZE = 8;
  38.           declare(RWGBitVec, VECSIZE)   // declare a 24 bit long vector
  39.           implement(RWGBitVec, VECSIZE) // implement the vector
  40.           main()
  41.           {
  42.             RWGBitVec(VECSIZE) a, b;   // Allocate two vectors.
  43.             a(2) = TRUE;               // Set bit 2 (the third bit) of a on.
  44.             b(3) = TRUE;               // Set bit 3 (the fourth bit) of b on.
  45.             RWGBitVec(VECSIZE) c = a ^ b;  // Set c to the XOR of a and b.
  46.             cout << "Vector 1" << "" << "Vector 2" << ""
  47.                  << "Vector 1 xor Vector 2" << endl;
  48.             for(int i = 0; i < VECSIZE; i++)
  49.               cout << a[i] << "" << b[i] << "" << c[i] << endl;
  50.             return 0;
  51.           }
  52.  
  53. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss
  54.               RRRRWWWWGGGGBBBBiiiittttVVVVeeeecccc(ssssiiiizzzzeeee)();
  55.  
  56.  
  57.      Construct a bit vector ssssiiiizzzzeeee elements long, with all bits initialized to
  58.      FFFFAAAALLLLSSSSEEEE.
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWGGGGBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))                                                RRRRWWWWGGGGBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.               RRRRWWWWGGGGBBBBiiiittttVVVVeeeecccc(ssssiiiizzzzeeee)(RWBoolean f);
  75.  
  76.  
  77.      Construct a bit vector ssssiiiizzzzeeee elements long, with all bits initialized to
  78.      ffff.
  79.  
  80. AAAAssssssssiiiiggggnnnnmmmmeeeennnntttt OOOOppppeeeerrrraaaattttoooorrrrssss
  81.               RWGBitVec(sz)&
  82.           ooooppppeeeerrrraaaattttoooorrrr====(const RWGBitVec(sz)& v);
  83.  
  84.  
  85.      Set each element of self to the corresponding bit value of vvvv.  Return a
  86.      reference to self.
  87.  
  88.               RWGBitVec(sz)&
  89.           ooooppppeeeerrrraaaattttoooorrrr====(RWBoolean f);
  90.  
  91.  
  92.      Set all elements of self to the boolean value ffff.
  93.  
  94.               RWGBitVec(sz)&
  95.           ooooppppeeeerrrraaaattttoooorrrr&&&&====(const RWGBitVec(sz)& v);
  96.           RWGBitVec(sz)&
  97.           ooooppppeeeerrrraaaattttoooorrrr^^^^====(const RWGBitVec(sz)& v);
  98.           RWGBitVec(sz)&
  99.           ooooppppeeeerrrraaaattttoooorrrr||||====(const RWGBitVec(sz)& v);
  100.  
  101.  
  102.      Logical assignments.  Set each element of self to the logical AAAANNNNDDDD, XXXXOOOORRRR,
  103.      or OOOORRRR, respectively, of self and the corresponding bit in vvvv.
  104.  
  105. IIIInnnnddddeeeexxxxiiiinnnngggg OOOOppppeeeerrrraaaattttoooorrrrssss
  106.               RWBitRef
  107.           ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](size_t i);
  108.  
  109.  
  110.      Returns a reference to the iiiith bit of self.  This reference can be used
  111.      as an lvalue.  The index iiii must be between 0000 and ssssiiiizzzzeeee----1111, inclusive.
  112.      Bounds checking will occur.
  113.  
  114.               RWBitRef
  115.           ooooppppeeeerrrraaaattttoooorrrr(((())))(size_t i);
  116.  
  117.  
  118.      Returns a reference to the iiiith bit of self.  This reference can be used
  119.      as an lvalue.  The index iiii must be between 0000 and ssssiiiizzzzeeee----1111, inclusive.  No
  120.      bounds checking is done.
  121.  
  122. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
  123.               void
  124.           cccclllleeeeaaaarrrrBBBBiiiitttt(size_t i);
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RRRRWWWWGGGGBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))                                                RRRRWWWWGGGGBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140.      Clears (i.e., sets to FFFFAAAALLLLSSSSEEEE) the bit with index iiii.  The index iiii must be
  141.      between 0 and ssssiiiizzzzeeee----1111.  No bounds checking is performed.  The following
  142.      are equivalent, although cccclllleeeeaaaarrrrBBBBiiiitttt((((ssssiiiizzzzeeee____tttt)))) is slightly smaller and faster
  143.      than using ooooppppeeeerrrraaaattttoooorrrr(((())))((((ssssiiiizzzzeeee____tttt)))):
  144.  
  145.                     a(i) = FALSE;
  146.  
  147.  
  148.  
  149.                     a.clearBit(i);
  150.  
  151.  
  152.  
  153.  
  154.               const RWByte*
  155.           ddddaaaattttaaaa() const;
  156.  
  157.  
  158.      Returns a const pointer to the raw data of self.  Should be used with
  159.      care.
  160.  
  161.               void
  162.           sssseeeettttBBBBiiiitttt(size_t i);
  163.  
  164.  
  165.      Sets (iiii....eeee...., sets to TTTTRRRRUUUUEEEE) the bit with index iiii.  The index iiii must be
  166.      between 0 and ssssiiiizzzzeeee----1111.  No bounds checking is performed.  The following
  167.      are equivalent, although sssseeeettttBBBBiiiitttt((((ssssiiiizzzzeeee____tttt)))) is slightly smaller and faster
  168.      than using ooooppppeeeerrrraaaattttoooorrrr(((())))((((ssssiiiizzzzeeee____tttt))))::::
  169.  
  170.                     a(i) = TRUE;
  171.  
  172.  
  173.  
  174.                     a.setBit(i);
  175.  
  176.  
  177.  
  178.  
  179.               RWBoolean
  180.           tttteeeessssttttBBBBiiiitttt(size_t i) const;
  181.  
  182.  
  183.      Tests the bit with index iiii.  The index iiii must be between 0 and ssssiiiizzzzeeee----1111.
  184.      No bounds checking is performed.  The following are equivalent, although
  185.      tttteeeessssttttBBBBiiiitttt((((ssssiiiizzzzeeee____tttt)))) is slightly smaller and faster than using
  186.      ooooppppeeeerrrraaaattttoooorrrr(((())))((((ssssiiiizzzzeeee____tttt)))):
  187.  
  188.                     if( a(i) ) doSomething();
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. RRRRWWWWGGGGBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))                                                RRRRWWWWGGGGBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))
  203.  
  204.  
  205.  
  206.                     if( a.testBit(i) ) doSomething();
  207.  
  208.  
  209.  
  210. RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll FFFFuuuunnnnccccttttiiiioooonnnnssss
  211.               RWGBitVec(sz)
  212.           ooooppppeeeerrrraaaattttoooorrrr&&&&(const RWGBitVec(sz)& v1, const RWGBitVec(sz)& v2);
  213.           RWGBitVec(sz)
  214.           ooooppppeeeerrrraaaattttoooorrrr^^^^(const RWGBitVec(sz)& v1, const RWGBitVec(sz)& v2);
  215.           RWGBitVec(sz)
  216.           ooooppppeeeerrrraaaattttoooorrrr||||(const RWGBitVec(sz)& v1, const RWGBitVec(sz)& v2);
  217.  
  218.  
  219.      Return the logical AAAANNNNDDDD, XXXXOOOORRRR, and OOOORRRR, respectively, of vectors vvvv1111 and vvvv2222.
  220.  
  221.               RWBoolean
  222.           ooooppppeeeerrrraaaattttoooorrrr========(const RWGBitVec(sz)& v1, const RWGBitVec(sz)& v2)
  223.                      const;
  224.  
  225.  
  226.      Returns TTTTRRRRUUUUEEEE if each bit of vvvv1111 is set to the same value as the
  227.      corresponding bit in vvvv2222.  Otherwise, returns FFFFAAAALLLLSSSSEEEE.
  228.  
  229.               RWBoolean
  230.           ooooppppeeeerrrraaaattttoooorrrr!!!!====(const RWGBitVec(sz)& v1, const RWGBitVec(sz)& v2)
  231.                      const;
  232.  
  233.  
  234.      Returns FFFFAAAALLLLSSSSEEEE if each bit of vvvv1111 is set to the same value as the
  235.      corresponding bit in vvvv2222.  Otherwise, returns TTTTRRRRUUUUEEEE.
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.